<template>
  <el-form
    ref="registerForm"
    :model="registerUser"
    :rules="registerRules"
    label-width="100px"
    class="registerForm sign-up-form"
  >
    <div @keyup.enter="userRegistoryEnter">
      <h3>Sky后台管理系统注册</h3>
      <el-form-item label="姓名" prop="nickName">
        <el-input v-model="registerUser.nickName" placeholder="请输入用户名"></el-input>
      </el-form-item>
      <el-form-item label="手机" prop="phone">
        <el-input v-model="registerUser.phone" placeholder="请输入手机号"></el-input>
      </el-form-item>
      <el-form-item label="账号" prop="username">
        <el-input v-model="registerUser.username" placeholder="请输入账号"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input
          v-model="registerUser.password"
          type="password"
          placeholder="请输入密码"
        ></el-input>
      </el-form-item>
      <el-form-item label="确认密码" prop="passwordConfirm">
        <el-input
          v-model="registerUser.passwordConfirm"
          type="password"
          placeholder="再次确认密码"
        ></el-input>
      </el-form-item>

      <el-form-item>
        <el-button
          @click="handleRegister"
          type="primary"
          class="submit-btn"
          >注册</el-button
        >
      </el-form-item>
    </div>
  </el-form>
</template>

<script>
import {userRegister} from '@/api/system/registerLoginApi'
export default {
  props: {
    registerUser: {
      type: Object,
      required: true,
    },
    registerRules: {
      type: Object,
      required: true,
    },
  },

  methods: {
    handleRegister() {
      this.$refs["registerForm"].validate((validate) => {
        if (validate) {
          userRegister(this.registerUser).then(data=>{
            this.reset();
            this.$message.success("注册成功");
          }).catch(err=>{
            this.$message.error(err);
          })
        } 
      });
      setTimeout(() => {
        this.$emit('toLogin')
      }, 3000);
    },
    userRegistoryEnter() {
      this.handleRegister();
    },
    reset(){
      this.$refs.registerForm.resetFields();
    }
  },
};
</script>

<style scoped lang="scss">
.submit-btn{
  width: 100%;
}
h3{
  position: relative;
  bottom: 10px;
  text-align: center;
  font-size: 18px;
  background-image: linear-gradient(135deg, #1d131f, #409eff);
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
  text-shadow: 1px 1px 3px rgb(128, 128, 128);
}
</style>
